﻿using System;
using System.Collections.Generic;
using System.Text;

namespace gChartSharp
{
    /// <summary>
    /// http://code.google.com/apis/chart/#chdl
    /// </summary>
    public class LegendParam : IChartParam
    {
        /// <summary>
        /// The name of the chart parameter
        /// </summary>
        public string Name { get { return "chdl"; } }


        /// <summary>
        /// The legend labels
        /// </summary>
        public List<string> DataSetLabels 
        {
            get { return mDataSetLabels ?? (mDataSetLabels = new List<string>()); }
            set { mDataSetLabels = value; }
        }
        private List<string> mDataSetLabels;


        /// <summary>
        /// The default constructor
        /// </summary>
        public LegendParam() { }


        /// <summary>
        /// Constructor that takes an array of labels
        /// </summary>
        /// <param name="labels"></param>
        public LegendParam(string[] labels)
        {
            foreach (string label in labels)
                this.DataSetLabels.Add(label);
        }


        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public string Render()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(String.Format("&{0}=", this.Name));

            foreach (string dataSetLabel in this.DataSetLabels)
            {
                sb.Append(dataSetLabel);
                sb.Append("|");
            }

            // remove last '|'
            if (sb.Length > 0)
                sb.Length--;

            return sb.ToString();
        }
    }
}
